package bigdata.backend.utils;

import java.util.regex.Pattern;

public class TableNameValidator {
    private static final Pattern VALID_NAME = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$");

    public static String validate(String name) {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("表名不能为空");
        }
        name = name.trim();
        if (!VALID_NAME.matcher(name).matches()) {
            throw new IllegalArgumentException("表名 '" + name + "' 不合法：必须以字母或下划线开头，仅包含字母、数字、下划线");
        }
        return name;
    }
}
